!(function (win) {
  /**
   * 长按功能，长按 700ms 以上即可调用回调方法
   *
   * @class
   */
  function isWindow(obj) {
    return obj != null && obj.window === obj;
  }
  function _onClickStart_(event) {
    var _this = this;
    // 清除默认行为
    event.stopPropagation();
    // event.preventDefault();
    _this.timer = setTimeout(() => {
      if (typeof _this.callback === "function") {
        _this.callback();
      } else {
        console.error("callback is not a function!");
      }
    }, _this.duration);
  }
  function _onClickEnd_(event) {
    var _this = this;
    // 清除默认行为
    event.stopPropagation();
    // event.preventDefault();
    clearTimeout(_this.timer);
  }

  function LongPress(el, opts) {
    opts =
      Object.prototype.toString.call(opts) === "[object Object]" ? opts : { callback: function () {}, duration: 700 };
    this.el = isWindow(window) ? window : document.querySelector(el);
    this.callback = opts.callback;
    this.duration = opts.duration;
    this.timer = null;
  }
  LongPress.prototype = {
    constructor: LongPress,
    listen: function () {
      var _this = this;
      _this.el.addEventListener("touchstart", _onClickStart_.bind(_this));
      _this.el.addEventListener("touchend", _onClickEnd_.bind(_this));
    },
    destroy: function () {
      var _this = this;
      _this.el.removeEventListener("touchstart", _onClickStart_.bind(_this));
      _this.el.removeEventListener("touchend", _onClickEnd_.bind(_this));
    },
  };

  win.LongPress = LongPress;
})(window);
